package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.dao.UserDao;
import com.itheima.entity.User;
import com.itheima.entity.dto.LoginDto;
import com.itheima.entity.vo.LoginUserVo;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;

    @Override
    public LoginUserVo login(LoginDto dto) {

        if (dto == null) {
            // TODO 参数异常
        }

        User user = userDao.selectByUserName(dto.getLoginName());

        if (user == null) { //代表用户不存在得
            // TODO 用户不存在时处理方式
        }
        if (!user.getPassword().equals(dto.getPassword())) { //代表密码错误
            // TODO 密码错误时在时处理方式
        }
        //密码相等
        LoginUserVo loginUserVo = new LoginUserVo();
        loginUserVo.setUserId(user.getId());
        loginUserVo.setUserName(user.getUserName());
        loginUserVo.setRoleCode(user.getRoleCode());
        loginUserVo.setSuccess(true);
        loginUserVo.setMsg("登录成功");
        return loginUserVo;
    }
}
